package com.nvn.washiodriver.adapters;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.nvn.washiodriver.R;
import com.nvn.washiodriver.Objects.ScheduleItem;
import com.nvn.washiodriver.utils.Statics;

public class ScheduleListAdapter extends BaseAdapter {

	private Context mContext;
	private ArrayList<ScheduleItem> items;
	private LayoutInflater mInflater;

	public ScheduleListAdapter(Context mContext, ArrayList<ScheduleItem> items) {
		this.mContext = mContext;
		this.items = items;
		mInflater = (LayoutInflater) mContext
				.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		final ScheduleItem s = getItem(position);
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_list_schedule, null);
		}

		TextView tvArea = (TextView) convertView.findViewById(R.id.tv_area);
		TextView tvDay = (TextView) convertView.findViewById(R.id.tv_day);
		TextView tvAM = (TextView) convertView.findViewById(R.id.tv_am);
		TextView tvPM = (TextView) convertView.findViewById(R.id.tv_pm);
		
		tvArea.setText(s.getArea());
		tvDay.setText(s.getDay());
		tvAM.setText(s.getMorning());
		tvPM.setText(s.getAfternoon());

		if (position % 2 == 0) { // EVEN
			convertView.setBackgroundResource(R.color.item_list_color_even);
		} else {
			convertView.setBackgroundResource(R.color.item_list_color_odd);
		}

		convertView.setMinimumHeight(Statics.PixelFromDp(mContext, 70));
		
		return convertView;
	}

	public void setData(ArrayList<ScheduleItem> items) {
		this.items = items;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public ScheduleItem getItem(int arg0) {
		return items.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}
}
